package org.jeecg.modules.unitGroup.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.unitGroup.entity.CyFactorUnitGroup;
import org.jeecg.modules.unitGroup.service.ICyFactorUnitGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

 /**
 * @Description: 碳排因子单位分组表
 * @Author: jeecg-boot
 * @Date:   2024-11-06
 * @Version: V1.0
 */
@Api(tags="碳排因子单位分组表")
@RestController
@RequestMapping("/CyFactorUnitGroup/cyFactorUnitGroup")
@Slf4j
public class CyFactorUnitGroupController extends JeecgController<CyFactorUnitGroup, ICyFactorUnitGroupService> {
	@Autowired
	private ICyFactorUnitGroupService cyFactorUnitGroupService;
	
	/**
	 * 分页列表查询
	 *
	 * @param cyFactorUnitGroup
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "碳排因子单位分组表-分页列表查询")
	@ApiOperation(value="碳排因子单位分组表-分页列表查询", notes="碳排因子单位分组表-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<CyFactorUnitGroup>> queryPageList(CyFactorUnitGroup cyFactorUnitGroup,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<CyFactorUnitGroup> queryWrapper = QueryGenerator.initQueryWrapper(cyFactorUnitGroup, req.getParameterMap());
		Page<CyFactorUnitGroup> page = new Page<CyFactorUnitGroup>(pageNo, pageSize);
		IPage<CyFactorUnitGroup> pageList = cyFactorUnitGroupService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param cyFactorUnitGroup
	 * @return
	 */
	@AutoLog(value = "碳排因子单位分组表-添加")
	@ApiOperation(value="碳排因子单位分组表-添加", notes="碳排因子单位分组表-添加")
	//@RequiresPermissions("org.jeecg.modules.demo:cy_factor_unit_group:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody CyFactorUnitGroup cyFactorUnitGroup) {
		cyFactorUnitGroupService.save(cyFactorUnitGroup);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param cyFactorUnitGroup
	 * @return
	 */
	@AutoLog(value = "碳排因子单位分组表-编辑")
	@ApiOperation(value="碳排因子单位分组表-编辑", notes="碳排因子单位分组表-编辑")
	//@RequiresPermissions("org.jeecg.modules.demo:cy_factor_unit_group:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody CyFactorUnitGroup cyFactorUnitGroup) {
		cyFactorUnitGroupService.edit(cyFactorUnitGroup);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "碳排因子单位分组表-通过id删除")
	@ApiOperation(value="碳排因子单位分组表-通过id删除", notes="碳排因子单位分组表-通过id删除")
	//@RequiresPermissions("org.jeecg.modules.demo:cy_factor_unit_group:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		Result<String> ResultMsg = cyFactorUnitGroupService.delete(id);
		return ResultMsg;
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "碳排因子单位分组表-通过id查询")
	@ApiOperation(value="碳排因子单位分组表-通过id查询", notes="碳排因子单位分组表-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<CyFactorUnitGroup> queryById(@RequestParam(name="id",required=true) String id) {
		CyFactorUnitGroup cyFactorUnitGroup = cyFactorUnitGroupService.getById(id);
		if(cyFactorUnitGroup==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(cyFactorUnitGroup);
	}

}
